<template>
  <div style="margin-top:30px">
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">

      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="所属机构" prop="branchCode" style="margin-right:15px">
              <partyGroupSelect ref="partyGroupSelect" @setPartyGroupCode="setPartyGroupCode" style="width: 100%"/>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="角色名称" prop="roleName" style="margin-right:15px">
              <el-input v-model="form.roleName" placeholder="请输入角色名称" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
<!--      <el-row>-->
<!--        <el-col :span="24">-->
<!--          <div class="grid-content bg-purple">-->
<!--            <el-form-item  prop="isCanalAudit" style="margin-right:15px">-->
<!--              <el-switch-->
<!--                v-model="isCanalAudit"-->
<!--                active-text="可以反审核"-->
<!--                inactive-text="不可以反审核" @change="changeValue($event)">-->
<!--              </el-switch>-->
<!--            </el-form-item>-->
<!--          </div>-->
<!--        </el-col>-->
<!--      </el-row>-->
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="备注" prop="description" style="margin-right:15px">
              <el-input v-model="form.description" placeholder="请输入备注" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="funcCancel">取 消</el-button>
      <el-button type="primary" @click="funcSubmit" :disabled="isDisable">确 定</el-button>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import request from '@/utils/request'
import partyGroupSelect from '@/views/components/partyGroupSelect.vue'
Vue.use(VXETable)
export default {
  name: 'RoleAdd',
  components: {
    partyGroupSelect
  },
  data() {
    return {
      isDisable:false,
      isCanalAudit:'',
      form: {
        roleName: '',
        description: '',
        isCanalAudit:0,
        branchCode:''
      },
      rules: {
        roleName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' },

        ],
        branchCode: [
          { required: true, message: '请选择所属机构', trigger: 'blur' },

        ]
      }
    }
  },
  created() {},
  methods: {
    changeValue(value){
      if (value == true){
        this.form.isCanalAudit = 0;
      }else{
        this.form.isCanalAudit = 1;
      }
      console.info("this.form.isCanalAudit",this.form.isCanalAudit)
    },
    // 重置
    reset(){
      this.$refs.partyGroupSelect.setSelectValue('')
      this.$refs['form'].resetFields()
    },

    // 选择组织机构
    setPartyGroupCode(value) {
      this.form.branchCode = value
    },
    // 提交
    funcSubmit() {
      console.info(this.form)
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.isDisable = true

          const rLoading = this.openLoading();
          const data = this.form
          request({ url: '/arpa-basic-api/role', method: 'post', params: data }).then(response => {
            rLoading.close();
            this.$message({ message: response.msg, type: 'success' })
            this.$emit('fatherAddMethod')
              this.isDisable = false

          }).then(() => {
              this.$refs.partyGroupSelect.setSelectValue('')
              this.$refs['form'].resetFields()

          }).catch(() => this.isDisable = false)

        } else {
          return false
        }
      })
    },
    // 取消
    funcCancel() {
      this.$emit('fatherCancelMethod', 'add')
    }
  }
}
</script>
<style lang="scss" scoped>
  .dialog-footer {
    margin:15px 0 15px 0;
    width: 175px;
    float: right;
  }
</style>
